﻿using Member.Domain.Entities;
using Member.Domain.IRepository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Member.Infrastructure.Repository
{
    public class AdminUserRepository : IAdminUserRepository
    {
        private readonly IRepository<AdminUser> _client;
        public AdminUserRepository(IRepository<AdminUser> client)
        {
            _client = client;
        }
        /// <summary>
        /// 根据用户名和密码获取用户信息
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        public async Task<AdminUser> GetEntityByPasswordAsync(string phone, string passWord)
        {
               return await _client.Context.Queryable<AdminUser>()
              .Where(x => x.phone == phone && x.password == passWord && x.isDel == 0)
              .FirstAsync();
        }
        /// <summary>
        /// 获取用户分页
        /// </summary>
        /// <param name="totalConut"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<AdminUser>> GetPageListAsync(RefAsync<int> totalConut, int page, int limit)
        {
            return await _client.Context.Queryable<AdminUser>()
            .Where(a => a.isDel == 0)
            .OrderByDescending(a => a.createTime)
            .ToOffsetPageAsync(page, limit, totalConut);
        }
    }
}
